//Given an integer array nums, move all 0's to the end of it while maintaining 
//the relative order of the non-zero elements. 
//
// Note that you must do this in-place without making a copy of the array. 
//
// 
// Example 1: 
// Input: nums = [0,1,0,3,12]
//Output: [1,3,12,0,0]
// Example 2: 
// Input: nums = [0]
//Output: [0]
// 
// 
// Constraints: 
//
// 
// 1 <= nums.length <= 10⁴ 
// -2³¹ <= nums[i] <= 2³¹ - 1 
// 
//
// 
//Follow up: Could you minimize the total number of operations done? Related 
//Topics Array Two Pointers 👍 6908 👎 193


package leetcode.editor.en;

public class _283_MoveZeroes {
    public static void main(String[] args) {
        Solution solution = new _283_MoveZeroes().new Solution();
        solution.moveZeroes(new int[]{2,1,0,0,12});
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public void moveZeroes3(int[] nums) {
            int l =0;
            for (int i = 0; i < nums.length; i++) {
                if (nums[i]!=0){
                    int temp = nums[i];
                    nums[i] = nums[l];
                    nums[l++] =temp;
                }
            }
        }


        public void moveZeroes2(int[] nums) {
            int slow = 0;
            for (int i = 0; i < nums.length; i++) {
                if (nums[i] !=0) {
                    int temp = nums[i];
                    nums[i] = nums[slow];
                    nums[slow++] = temp;
                }
            }
        }
        public void moveZeroes1(int[] nums) {
            int slow = 0;
            for (int i = 0; i < nums.length; i++) {
                if (nums[i]!=0) {
                    int temp = nums[i];
                    nums[i] = nums[slow];
                    nums[slow++] = temp;
                }
            }
        }



        public void moveZeroes(int[] nums) {
            int j = 0;
            for (int i = 0; i < nums.length; i++) {
                if (nums[i] != 0) {
                    int temp = nums[i];
                    nums[i] = nums[j];
                    nums[j++] = temp;
                }
            }
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}